package com.zhouheng.springbootmultithreading.tuling.hashMap;

import com.zhouheng.springbootmultithreading.tuling.hashMap.threadpool.MyTask;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 自定义拒绝策略
 */
public class MonkeyRejectedExecutionHandler implements RejectedExecutionHandler {

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (r instanceof MyTask) {
            MyTask myTask = (MyTask) r;
            // 写数据库的代码
            System.out.println("保存拒绝的项目" + myTask.getI() + "到数据库,");
        }
    }

}
